#-*- coding:utf-8 -*-
import requests,urllib,os
from bs4 import BeautifulSoup

ans = 0
os.chdir(os.path.join(os.getcwd(),'photos'))
for page in range(1,2):
    if page==1:
        url='https://www.gamersky.com/news/201903/1162273.shtml?toutiao'
    else:
        url='https://www.gamersky.com/news/201903/1162273_2.shtml'
    header = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.109 Safari/537.36'}
    source_code = requests.get(url,headers=header)
    source_code.encoding = 'utf-8' #解决乱码问题
    plain_text = source_code.text
    soup = BeautifulSoup(plain_text,'lxml')

    download_links = []
    #folder_path = 'C:\Users\kyon\Desktop\Graduation\photos'
    for pic_tag in soup.find_all('img'):
        pic_link = pic_tag.get('src')
        pic_name = pic_tag.get('alt')+".jpg"
        urllib.request.urlretrieve(pic_link,pic_name);
        print(pic_link)
        print(pic_name)
        
    
    
